import axios from 'axios';
import * as actionTypes from './actionTypes';
import { fromJS } from 'immutable';

const initDetail = (title, content) => ({
	type: actionTypes.GET_DETAIL,
	title: fromJS(title),
	content: fromJS(content)
});

export const getDetail = (id) => {
	return (dispatch) => {
		axios.get('/mock/detail.json?id=' + id).then(res => {
			const result = res.data.data;
			dispatch(initDetail(result.title, result.content));
		}).catch(err => {
			console.log('请求失败');
		})
	}
}